/**
 * Created by chenxiaozhong on 2016年1月5日16:51:26.
 */
define(["app",
    "controllers/showtimes/AddUserController"
], function (app) {

    var deps = ["$modal","$window","$state"];

    function addUser($modal,$window,$state) {
        return {
            scope : {
            	companyCode : "@",
            	companyName : "@",
            	singleCallPrice : "@",   
            	conferencePrice : "@",
            	onSelect : "&onSelect"
            },
            link: function ($scope, elem) {
                elem.on("click", function () {
                    var modalInstance = $modal.open({
                        templateUrl: 'views/showtimes/AddUser.html',
                        controller: "AddUserController",
                        backdrop : "static",
                        keyboard: false,
                        resolve : {
                        	companyCode : function() {
                                return $scope.companyCode;
                            },
                            companyName : function(){
                                return $scope.companyName;
                            },
                            singleCallPrice : function(){
                                return $scope.singleCallPrice;
                            },
                            conferencePrice : function(){
                                return $scope.conferencePrice;
                            }
                        },
                        windowClass : "conpany-add-modal"
                    });

                    modalInstance.result.then(function(data) {
                    	$scope.userVo = [];
                    	if(data!=null){
                    		$scope.userVo.push(data);
                    		if($scope.onSelect) {
                                $scope.onSelect({$choseUser:$scope.userVo});
                            }
                    	}
                    	//$state.go("home.financialManagement");
                    	//$scope.$emit('userAddBroadCast');
                    });
                });
                
            }
        };
        
    }

    addUser.$inject = deps;
    return app.lazy.directive("fcAddUser", addUser);
});